package cq.zhcqk.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.dou361.dialogui.DialogUIUtils;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.zzhoujay.richtext.RichText;

import org.apache.http.Header;
import org.json.JSONObject;

import java.util.Map;

import cq.zhcqk.R;
import cq.zhcqk.base.BaseActivity;
import cq.zhcqk.util.Common;
import cq.zhcqk.util.GsonUtil;
import cq.zhcqk.util.StringUtil;

/**
 * Created by zhangle on 2017/12/12.
 */
public class SQ_Yjjy_DetailActivity extends BaseActivity implements View.OnClickListener{
    private TextView title;
    private TextView fb_time;
    private TextView hf_time;
    private TextView content;
    private String id;
    Map<String, Object> mapData;
    @Override
    protected void initView() {
        setContentView(R.layout.activity_yjjy_detail);
        initBack();
        title = (TextView) findViewById(R.id.title);
        fb_time = (TextView) findViewById(R.id.fb_time);
        hf_time = (TextView) findViewById(R.id.hf_time);
        content = (TextView) findViewById(R.id.content);
        id = getIntent().getStringExtra("cid");
    }

    @Override
    protected void initData() {
        getDetail();
    }

    private void initBack(){
        ImageView back = (ImageView) findViewById(R.id.header_back);
        TextView title = (TextView) findViewById(R.id.header_text);
        title.setText("意见建议");
        back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.header_back:
                finish();
                break;
        }
    }

    private void setData(){
        title.setText(mapData.get("var02")+"");
        fb_time.setText("发布时间："+mapData.get("createdate")+"");
        hf_time.setText("回复时间："+StringUtil.parseNull(mapData.get("updatename")+""));
        content.setText("建议内容："+mapData.get("conten")+"");
    }

    private void getDetail(){
        buildBean.show();
        RequestParams params = new RequestParams();
        params.add("id",id);
        httpClient.post(Common.URL+Common.SUGGESTIONDETAIL,params,new JsonHttpResponseHandler(){
            @Override
            public void onSuccess(int statusCode, Header[] headers,
                                  JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                System.out.println("onSuccess："+response);
                Map<String, Object> map = GsonUtil.GsonToMaps(response+"");
                if(map != null && map.size()>0){
                    mapData = (Map<String, Object>) map.get("data");
                    if(mapData != null && mapData.size()>0){
                        setData();
                    }
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers,
                                  Throwable throwable, JSONObject errorResponse) {
                super.onFailure(statusCode, headers, throwable,
                        errorResponse);
                Toast.makeText(context,"获取失败，请稍后再试",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                Toast.makeText(context,"获取失败，请稍后再试",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                DialogUIUtils.dismiss(buildBean);
            }
        });
    }
}
